<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="../../css/oksub.css">
	<script type="text/javascript" src="../../lib/loading/okLoading.js"></script>
	<style type="text/css">
	 .layui-table-tool{
	    display:none;
	  }	
	</style>
</head>
<body>
<div class="ok-body">
	<!--form表单-->
	<form class="layui-form layui-form-pane ok-form">
		<div class="layui-form-item">
			<label class="layui-form-label">SCAN</label>
			<div class="layui-input-block">
				<input type="text" id="code" name="code" placeholder="請掃瞄 REG LABEL" autocomplete="off" class="layui-input"	 lay-verify="required">
			</div>
		</div>	
	</form>
	 <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<!--js逻辑-->
<script src="../../lib/layui/layui.js"></script>
<script src="../../js/okform.js"></script>
<script>
    var timestamp = "";
    var regCodeCount = 0;
    var GROUP_CODE_ID = request("GROUP_CODE_ID");
	layui.use(["element", "form","jquery","table", "laydate", "okLayer", "okUtils", "okMock"], function () {
		let form = layui.form;
		let laydate = layui.laydate;
		let okLayer = layui.okLayer;
		let okUtils = layui.okUtils;
		let table = layui.table;
		let okMock = layui.okMock;
		let $ = layui.jquery;
		
		okLoading.close();		
		timestamp = $.now();
		$("#code").focus();
		
		
		$('#code').bind('keydown', function(event) {
		  　　if (event.keyCode == "13") { 
		      var _CODE= $('#code').val();		     
		      okUtils.ajax("RegCodeServlet?method=save", "get", {GROUP_CODE_ID:GROUP_CODE_ID,CODE: _CODE}, true).done(function (response) {		         
				    stable.reload();
				    regCodeCount++;
				    if(regCodeCount == 10){
				        layer.alert("請注意，已掃描10個標籤");				       
				    }
				}).fail(function (error) {
					console.log(error)
				});
		      $('#code').val("");
		      return false;
		  　　}
		  });
		
		var  searchcondition =JSON.stringify({ GROUP_CODE_ID :GROUP_CODE_ID});
		let stable = table.render({
			elem: '#tableId',
			url: "../../RegCodeServlet?method=getList",	
			toolbar: true,
			size: "sm",
			defaultToolbar: false,
			where: {searchcondition: searchcondition},
			cols: [[			
				{field: "XUHAO",title: "ID", width: 100},
				{field: "ID", title: "id", width: 100, hide: true},
				{field: "CODE", title: "REG_CODE", width: 200},
				{field: "S_CREATETIME", title: "TIME", width: 200},
				{title: "操作", width: 100, align: "center", fixed: "right", templet: "#operationTpl"}
			]],
			done: function (res, curr, count) {
				console.info(res, curr, count);
			}
		});
	
		
		function del(_ID) {
			okLayer.confirm("SURE DELETE ?", function () {			  
				okUtils.ajax("RegCodeServlet?method=delete", "get", {ID:_ID}, true).done(function (response) {
				    stable.reload();
					okUtils.tableSuccessMsg(response.msg);
					$("#code").focus();
				}).fail(function (error) {
					console.log(error)
				});
			})
		}
		
		table.on("tool(tableFilter)", function (obj) {
			let data = obj.data;
			switch (obj.event) {				
				case "del":
					del(data.ID);
					break;
			}
		});		
	});
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">

	<a href="javascript:" title="删除" lay-event="del"><i class="layui-icon">&#xe640;</i></a>
</script>
</body>
</html>
